// 订阅图像节点源文件

#include "Subscriber_node.hpp"

using namespace std::placeholders;

ImgSubscriber::ImgSubscriber() : Node("image_subscriber")
{
    sub_ = image_transport::create_subscription(this, "image", 
           std::bind(&ImgSubscriber::sub_image, this, _1), "raw");
    RCLCPP_INFO(this->get_logger(), "订阅器已启动，正在查看图像。话题: image");
}

void ImgSubscriber::sub_image(const sensor_msgs::msg::Image::ConstSharedPtr& msg)
{
    cv::Mat image = cv_bridge::toCvShare(msg, "bgr8")->image;
    cv::imshow("Armor_Detector", image);
    cv::waitKey(30);
}

int main(int argc, char **argv)
{
    rclcpp::init(argc, argv);
    auto node = std::make_shared<ImgSubscriber>();
    cv::namedWindow("Armor_Detector", cv::WINDOW_NORMAL);
    rclcpp::spin(node);
    cv::destroyAllWindows();
    rclcpp::shutdown();
    return 0;
}